﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;


using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Paper.Entiry;

public partial class sysadmin_QuestionManager_ShowPaperInfoTemp : PowerCreator.LMS.Web.Base.BasePage
{
    const string NEWTEXT = "<input id={0} type=\"text\" Class=\"myline\"  />";
    string QEUSTIONINDEX = "";

    ManagerPaper objManagerPaper = new ManagerPaper();
    ManagerQuestion objManagerQuestion = new ManagerQuestion();



    public string ispanduancz = "0";
    public string isdancz = "0";
    public string isgaiz = "0";
    public string isduocz = "0";
    public string istiancz = "0";
    public string isyuecz = "0";
    public string iswantcz = "0";
    public string iswangcz = "0";
    public string iscaocz = "0";
    public string iszuocz = "0";
    public int thi = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        QEUSTIONINDEX = "<span class=\"font_bule\">【" + GetLanageValueByKey("theme_Paper_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page) + "{0}" + GetLanageValueByKey("theme_Paper_Msg2", PowerCreator.LMS.Language.LanagetItemType.Page) + "】</span>";
        if (!IsPostBack)
        {
            ViewState["PaperID"] = Request.QueryString["p"].ToString();
            PageLoad();
            //ViewState["UserID"] = Base64.Decode(Request.QueryString["uid"].ToString());
            //ViewState["ProjectID"] = Base64.Decode(Request.QueryString["ProjectID"].ToString());
            //ViewState["ClassID"] = Base64.Decode(Request.QueryString["ClassID"].ToString());
            Band_dlst_panduan();//判断
            BindDLti1();//单选

            BindDLti2();//多选

            BindDLti3();//填空
            BindDLti4();//名词解释
            BindDLti5();//简答
            //BindDL_zuhe();//组合题

            InitPage();


        }

    }

    protected override void InitPage()
    {
        lab_PaperNameTitle.Text = GetLanageValueByKey("lab_EditUserPaper_PaperName", PowerCreator.LMS.Language.LanagetItemType.Page);


        lab_Panduan.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Panduanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Danxuan.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Danxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Duoxuan.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Duoxuanti", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Tiankong.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Tiankongti", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Mingcijieshi.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Mingcijieshiti", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_Jiandati.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Jiandati", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lab_Zuheti.Text = GetLanageValueByKey("lab_EditUserPaper_Question_Zuheti", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    private void PageLoad()
    {
        lab_PaperName.Text = objManagerPaper.LoadPaperResearch(int.Parse(ViewState["PaperID"].ToString())).PaperResearch_Name;
    }

    #region Web 判断题生成代码

    private void Band_dlst_panduan()
    {
        string search = " and Question.FKQuestionTypeID=1 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_panduan.Visible = false;
        }
        dlst_panduanti.DataSource = dt;
        dlst_panduanti.DataKeyField = "QuestionID";
        dlst_panduanti.DataBind();
    }
    protected void dlst_panduanti_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        //string a = e.Item.ItemType.GetType().ToString();

        string QuestionID = dlst_panduanti.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);




        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)

        Label LBtx = (Label)e.Item.FindControl("LBtx");
        //if (ispanduancz == "0")
        //{
        //    ispanduancz = "1";
        //}
        //else
        //{
        //    Label LBfg = (Label)e.Item.FindControl("LBfg");         //画题目分割线
        //    LBfg.Text = "<hr noshade width='100%' size='1'>";
        //    ispanduancz = "1";
        //}

        Label LBsm1 = (Label)e.Item.FindControl("LBsm1");
        RadioButtonList answerList1 = (RadioButtonList)e.Item.FindControl("AnswerList1");
        if (answerList1 != null)
        {
            LBsm1.Text = string.Format(QEUSTIONINDEX,thi.ToString()) + QuestionContent;

            thi = thi + 1;
            BindAnswerList(answerList1, QuestionID, LBsm1);
            Label LBdantiid = (Label)e.Item.FindControl("LBdantiid");  //取得题目id
            LBdantiid.Text = QuestionID;
        }

        Label LBdanra = (Label)e.Item.FindControl("LBdanra");    //取得题目正确答案
        LBdanra.Text = dt.Rows[0]["QuestionAnswer"].ToString().Trim();

    }
    #endregion

    #region Web 单选题生成代码
    private void BindDLti1()
    {
        string search = " and Question.FKQuestionTypeID=2 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_danxuan.Visible = false;
        }
        DLti1.DataSource = dt;
        DLti1.DataKeyField = "QuestionID";
        DLti1.DataBind();
    }
    protected void DLti1_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        string QuestionID = DLti1.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);

        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)

        Label LBtx = (Label)e.Item.FindControl("LBtx");

        Label LBsm1 = (Label)e.Item.FindControl("LBsm1");
        RadioButtonList answerList1 = (RadioButtonList)e.Item.FindControl("AnswerList1");
        if (answerList1 != null)
        {
            LBsm1.Text = string.Format(QEUSTIONINDEX, thi.ToString()) + QuestionContent;

            thi = thi + 1;
            BindAnswerList(answerList1, QuestionID, LBsm1);
            Label LBdantiid = (Label)e.Item.FindControl("LBdantiid");  //取得题目id
            LBdantiid.Text = QuestionID;
        }

        Label LBdanra = (Label)e.Item.FindControl("LBdanra");    //取得题目正确答案
        LBdanra.Text = dt.Rows[0]["QuestionAnswer"].ToString().Trim();


    }
    #endregion

    #region 绑定单选按钮答案

    /// <summary>
    /// 绑定单选按钮答案

    /// </summary>
    /// <param name="radioList">单选按钮集合</param>
    /// <param name="tiid">题目ID</param>
    private void BindAnswerList(RadioButtonList radioList, string QuestionID, Label lab_kongjian)
    {
        string str = " FKQuestionOptionQuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestionOption(str);
        radioList.DataSource = dt;
        radioList.DataTextField = "QuestionOptionContent";//答案
        radioList.DataValueField = "QuestionOptionID";//标题
        radioList.DataBind();
        ArrayList objlist = new ArrayList();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            radioList.Items[i].Text = radioList.Items[i].Text;
        }
    }

    #endregion

    #region Web 多选题生成代码
    private void BindDLti2()
    {
        string search = " and  Question.FKQuestionTypeID=3 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_duoxuan.Visible = false;
        }
        DLti2.DataSource = dt;
        DLti2.DataKeyField = "QuestionID";
        DLti2.DataBind();

    }

    public void DLti2_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
        string QuestionID = DLti2.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);

        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)

       

        CheckBoxList CheckList2 = (CheckBoxList)e.Item.FindControl("CheckList2");
        if (CheckList2 != null)
        {
            Label LBsm2 = (Label)e.Item.FindControl("LBsm2");

            LBsm2.Text = string.Format(QEUSTIONINDEX, thi.ToString()) + QuestionContent;
            thi = thi + 1;
            BindCheckList(CheckList2, QuestionID, LBsm2);
            Label LBduotiid = (Label)e.Item.FindControl("LBduotiid");  //取得题目id
            LBduotiid.Text = QuestionID;
        }


        Label LBduora = (Label)e.Item.FindControl("LBduora");    //取得题目正确答案
        LBduora.Text = dt.Rows[0]["QuestionAnswer"].ToString().Trim();
    }
    #endregion

    #region 绑定多选筐答案
    /// <summary>
    /// 绑定多选筐答案
    /// </summary>
    /// <param name="checkList"> 多选筐列表</param>
    /// <param name="tiid">题目ID</param>
    private void BindCheckList(CheckBoxList checkList, string QuestionID, Label lab_kongjian)
    {
        string str = " FKQuestionOptionQuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestionOption(str);
        checkList.DataSource = dt;
        checkList.DataTextField = "QuestionOptionContent";//答案
        checkList.DataValueField = "QuestionOptionID";//标题
        checkList.DataBind();
        ArrayList objlist = new ArrayList();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            checkList.Items[i].Text = checkList.Items[i].Text;
        }

    }

    #endregion

    #region Web 填空题生成代码

    private void BindDLti3()
    {
        string search = " and  Question.FKQuestionTypeID=4 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_tiankong.Visible = false;
        }
        DLti3.DataSource = dt;
        DLti3.DataKeyField = "QuestionID";
        DLti3.DataBind();
    }

    public void DLti3_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
        string QuestionID = DLti3.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);

        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)
        StringBuilder newQuestionContent = new StringBuilder();

        string[] str_QuestionContent = QuestionContent.Split('_');

        for (int i = 0; i < str_QuestionContent.Length; i++)
        {
            string textID = string.Format(NEWTEXT, "newtext_" + i.ToString());
            if (i < str_QuestionContent.Length - 1)
            {

                newQuestionContent.Append(str_QuestionContent[i] + textID);
            }
            else
            {
                newQuestionContent.Append(str_QuestionContent[i]);
            }

        }

        Label LBsmtk = (Label)e.Item.FindControl("LBsmtk");  //取得题目说明
        if (LBsmtk != null)
        {
            LBsmtk.Text = string.Format(QEUSTIONINDEX, thi.ToString()) + newQuestionContent;

            thi = thi + 1;
        }


        Label LBtkra = (Label)e.Item.FindControl("LBtkra");     //取得题目答案
        LBtkra.Text = dt.Rows[0]["QuestionAnswer"].ToString().Trim();
    }
    #endregion

    #region 名词解释
    private void BindDLti4()
    {
        string search = " and  Question.FKQuestionTypeID=5 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_mingcijieshi.Visible = false;
        }
        DLti4.DataSource = dt;
        DLti4.DataKeyField = "QuestionID";
        DLti4.DataBind();
    }

    public void DLti4_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
        string QuestionID = DLti4.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);

        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)

        Label LBjdftiid = (Label)e.Item.FindControl("LBjdftiid");  //取得题目id
        LBjdftiid.Text = QuestionID;

        Label LBsmjdf = (Label)e.Item.FindControl("LBsmjdf");  //取得题目说明
        if (QuestionContent != "")
        {
            LBsmjdf.Text = string.Format(QEUSTIONINDEX, thi.ToString()) + QuestionContent;

            thi = thi + 1;
        }
    }
    #endregion

    #region Web 简答

    private void BindDLti5()
    {
        string search = " and  Question.FKQuestionTypeID=6 and PaperResearchQuestionTemp.FKPRQTempPaperID=" + ViewState["PaperID"].ToString(); ;
        DataTable dt = objManagerPaper.GetPaperResearchTempQuestionList(search);
        if (dt.Rows.Count == 0)
        {
            pn_jiandati.Visible = false;
        }
        DLti5.DataSource = dt;
        DLti5.DataKeyField = "QuestionID";
        DLti5.DataBind();

    }

    public void DLti5_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
        string QuestionID = DLti5.DataKeys[e.Item.ItemIndex].ToString().Trim();//获取题号
        string str = " QuestionID=" + QuestionID;
        DataTable dt = objManagerQuestion.QueryQuestion(str);//根据题号从题库获取列表
        DataTable dt_questionTemp = objManagerPaper.QueryPaperResearchQuestionTemp(" FKPRQTempPaperID=" + ViewState["PaperID"].ToString() + " and FKPRQTempQuestionID=" + QuestionID);

        string QuestionContent = dt_questionTemp.Rows[0]["PRQTempQuestionContent"].ToString();//获取问题题干(从临时卷子试题表取得)

        Label LBjdftiid = (Label)e.Item.FindControl("LBjdftiid");  //取得题目id
        LBjdftiid.Text = QuestionID;

        Label LBsmjdf = (Label)e.Item.FindControl("LBsmjdf");  //取得题目说明

        LBsmjdf.Text = string.Format(QEUSTIONINDEX, thi.ToString()) + QuestionContent;

        thi = thi + 1;
    }
    #endregion

}
